<extend name="./Application/Admin/View/Public/base.html" />
<block name="eosi-css">
    <link href="__PUBLIC__/assets/css/daterangepicker.css?v=13" rel="stylesheet">
</block>

<block name="eosi-js"> 
    <script src="__PUBLIC__/assets/js/date-time/bootstrap-datepicker.min.js"></script>
    <script src="__PUBLIC__/assets/js/jqGrid/jquery.jqGrid.min.js"></script>
    <script src="__PUBLIC__/assets/js/jqGrid/i18n/grid.locale-en.js"></script>
    <script src="__PUBLIC__/assets/js/jqGrid/i18n/jquery.min.js"></script>
    <script src="__PUBLIC__/assets/js/jqGrid/i18n/super_slider.js"></script>
    <script type="text/javascript">
                var $path_base = "/"; 
    </script>

</block>
<block name="page-content">
    <div style="padding-bottom:5px;">
                <button class="btn btn-primary btn-xs" onclick="location.href = '{:U('addRule')}'">添加首页KV</button>
    </div>
    <div  class=""  style="height: 40px;">
        <span class="input-icon">
            <input type="text" placeholder="查询名称"   value="{$name}"
            class="nav-search-input" id="name" autocomplete="off" /> 
        </span>
        <span class="input-icon">
            <select  id="status">
                <option  value="">状态查询</option>
                <option <if condition="$status == 1"> selected </if>  value="1">启用</option>
                <option <if condition="is_numeric($status) && $status == 0"> selected </if>  value="0">禁用</option>
            </select>
        </span>
        <input type="button" id="search" value="查询"/>
        <input type="button" id="resetBt" value="重置筛选条件" />
         
    </div>
    <div class="row">
        <div class="col-xs-12">
            <table class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th>名称</th>
                        <th>显示图片</th>
                        <th>创建时间/更新时间</th>
                        <!-- <th><a href="javascript:void(0)" title="值越大越靠前显示,值相同最近更新的靠前显示">显示顺序</a></th> -->
                        <th>状态(同时只允许一张KV状态为启用)</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <volist name="_list" id="vo">
                        <tr>
                            <td>{$vo.name}</td>                  
                            <td  style="width: 200px;">
                                <img src="{$vo.img}"  style="max-width: 100%"/>
                            </td>
                            <td>{$vo.create_time}<br/>{$vo.update_time}</td>
                            <!-- <td>{$vo.show_order}</td> -->
                            <td id="status{$vo.id}" name="status_td" index="{$vo.id}">{$vo.status_str}</td>
                            <td>
                                <span class=" icon-pencil blue" title="编辑" style="cursor: pointer;" onclick="editRule({$vo.id});"></span>
                                &nbsp;&nbsp;
                                <span class=" icon-trash red" title="删除" style="cursor: pointer;" onclick="delRule({$vo.id});"></span>
                            </td>
                        </tr>
                    </volist>
                </tbody>
            </table>
            <div class="pager">{$_page}</div>
        </div>
    </div><!-- /.row -->

    <script type="text/javascript">
    $("#resetBt").click(function(){
            location.href = "/Admin/BhKv/index";
        });
         $("#search").click(function(){
            var name=$('#name').val();
            var status=$('#status').val();
            var url = '';
            if(name !='' && name != 1){
                url += "name="+name;
            }
            if(status !=''){
                url += url ? "&status="+status : "status="+status;
            }
            if (url) {
                location.href = "/Admin/BhKv/index?"+url;
            } else {
                location.href = "/Admin/BhKv/index";
            }
        }); 
    // 状态切换  ajax
        $(document).ready(function(){
                $('body').on('click', '.hand', function(){
                    var ad ={};
                    ad['id'] = $(this).attr('index');
                    ad['type'] =$(this).prev().text();
                    var id = $(this).attr('index');
                    var type = $(this).prev().text();
                    $.ajax({
                        cache:false,
                        type: "POST",
                        url: "__APP__/Admin/BhKv/status_change",
                        data:ad,
                        error:function(){
                            alert("网络原因修改失败,请稍候再试");
                        },
                        success:function(data){                        
                            if(data.status==1){    
                                $('[name="status_td"]').each(function(i, e){
                                    var s_id = $(this).attr('index');
                                    var wuxiao = "<span class=\"label label-sm label-info arrowed-in\"  style=\'cursor: pointer;\'>禁用</span>&nbsp;|&nbsp;&nbsp;&nbsp;<span class=\"hand icon-unlock green bigger-125\" title=\"启用\" style=\"cursor: pointer;\" index='" + s_id + "' ></span>";
                                    var youxiao = "<span class=\"label label-sm label-success arrowed-in\" style=\'cursor: pointer;\'>启用，显示在首页</span>&nbsp;|&nbsp;&nbsp;&nbsp;<span class=\"hand icon-lock red bigger-125\" style=\"cursor: pointer;\" title=\"禁用\"  index='" + s_id + "' ></span>";
                                    if (type == '禁用') {
                                        current_status = youxiao ;
                                    } else {
                                        current_status = wuxiao;
                                    }
                                    // ---------------
                                    if($(this).attr('index') == id) {
                                        $('#status' + id).html(current_status);
                                    } else if(type == '禁用') {
                                        $(this).html(wuxiao);
                                    }
                                });
                                if(data.info!='ok'){
                                    art.dialog.alert(data.info);
                                }
                            }else{
                                art.dialog.alert(data.info);
                        }
                    }
                    });
            });
        }) 
    //编辑任务
        function editRule(ruleid){
            location.href = "/Admin/BhKv/editRule/id/" + ruleid;
        }
    //删除任务
        function delRule(ruleid){
            art.dialog.confirm('确定删除?', function () {
                $.ajax({
                    type: "POST",
                    url: "__CONTROLLER__/deleteRule",
                    dataType: 'json',
                    data: {id:ruleid},
                    async: false,
                    error:function(){
                        art.dialog.alert("操作失败");
                    },
                    success: function(data){
                        if (data.status == 1) {
                            location.href = "__CONTROLLER__/index"; //刷新
                        } else {
                            art.dialog.alert(data.info);
                        }
                    }
                });
            });
        }
    //设置任务状态 open:开启  close:关闭
        function setStatus(type, ruleid){
            $.ajax({
                type: "POST",
                url:"__CONTROLLER__/setRuleStatus",
                dataType: 'json',
                data: {id:ruleid, type:type},
                success: function(data){
                    if (data.status == 1) {
                        location.href = "__CONTROLLER__/rule";
                    } else{
                        art.dialog.alert(data.info);
                    }
                },
                error:function(){
                    art.dialog.alert("操作失败");
                }
            });
        }
    </script>
    <script type="text/javascript">
        
        <volist name="_list" id="vo">
            $(".box{$vo.id}").superSlider({
                prevBtn:     ".prev{$vo.id}",//左按钮
                nextBtn:     ".next{$vo.id}",//右按钮
                listCont:    ".roll{$vo.id}",//滚动列表外层
                scrollWhere: "next",//自动滚动方向next
                delayTime:   2000,//自动轮播时间间隔
                speed:       300,//滚动速度
                amount:      1,//单次滚动数量
                showNum:     1,//显示数量
                autoPlay:    true//自动播放
            });
        </volist>
    </script>
</block>